package com.zx.servicelearn.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RemoteViews;

import com.zx.servicelearn.R;

/**
 * 客户端A：用于构造一个RemoteView，传递到客户端B
 */
public class RemoteViewLearnActivity1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remote_view_learn1);
    }

    public static String REMOTE_ACTION = "com.zx.servicelearn.remote.action";
    public static String EXTRA_REMOTE_VIEWS = "extra_remote_views";

    /**
     * 构造remoteView，发送广播
     *
     * @param view
     */
    public void setViewToClintB(View view) {
        final RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_notification);


        remoteViews.setTextViewText(R.id.my_tv, "lalala");


        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    remoteViews.setProgressBar(R.id.my_pb, 100, i, false);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

        Intent intent = new Intent(REMOTE_ACTION);
        intent.putExtra(EXTRA_REMOTE_VIEWS, remoteViews);
        sendBroadcast(intent);
    }


}
